package util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DataSourceTool {
    // 依赖druid.properties
    public static DataSource createDruidSource() throws Exception {
        //数据源配置
        Properties properties = new Properties();
        //通过当前类的class对象获取资源文件 读取配置文件流
        InputStream is = DataSourceTool.class.getResourceAsStream("/druid.properties");
        // 加载并读取配置
        properties.load(is);
        //通过工厂使用配置产生一个数据源
        return DruidDataSourceFactory.createDataSource(properties);
    }

    // 依赖 c3p0-config.xml
    public static DataSource createC3p0Source() {
        return new ComboPooledDataSource();
    }

}
